import sys
import re

xdb_args = dict(
    host='127.0.0.1',
    port=3306,
    user='test',
    password='testA1-',
    database='test',
    charset='utf8'
)


xregexp = re.compile(r'^\s*\d+(?:\.\d+){3}\s*$')
for xarg in sys.argv:
    if xregexp.match(xarg):
        xdb_args['host'] = xarg
        break


def xexec(xcursor, xsql):
    xrows_cnt = xcursor.execute(xsql)
    return xrows_cnt


def xquery(xcursor, xsql):
    xexec(xcursor, xsql)
    return xcursor.fetchall()
